# -*- coding: utf-8 -*-
# !/usr/bin/env python
import uvicorn
from fastapi import Depends, FastAPI, Query, Header, Cookie, Form, File, UploadFile
from pydantic import BaseModel
from typing import Optional
from apps.config import *
from apps.routers import users, items, files, tables, echarts
from starlette.requests import Request
from starlette.responses import RedirectResponse
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates
from starlette.responses import FileResponse
from tools import *

app = FastAPI()
app.include_router(users.router, prefix="/users", tags=["users"])
app.include_router(items.router, prefix="/items", tags=["items"])
app.include_router(files.router, prefix="/files", tags=["files"])
app.include_router(tables.router, prefix="/tables", tags=["tables"])
app.include_router(echarts.router, prefix="/echarts", tags=["echarts"])

templates = Jinja2Templates(directory="./templates")
app.mount("/static", StaticFiles(directory="./static"), name="static")


@app.get('/')
def homepage(request: Request):
    return templates.TemplateResponse('./homepage/index.html', {'request': request})


@app.get('/line')
def index(request: Request):
    db = DB()
    df = db.read_sql("select * from main.users")
    items = dict(df[['user_id', 'name']].values)
    db.close()
    return templates.TemplateResponse('timeline.html', {'request': request, 'items': items})


if __name__ == '__main__':
    uvicorn.run("main:app", host=Host, port=Port, debug=Debug)
